﻿using Domain.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Config
{
    public class UserConfig : IEntityTypeConfiguration<User>
    {
        public void Configure(EntityTypeBuilder<User> builder)
        {
            builder.ToTable("Users");
            builder.Property("passwordHash").HasMaxLength(127).IsUnicode(false);
            builder.OwnsOne(u => u.Phone, pn => { 
                pn.Property(p=>p.RegionCode).HasMaxLength(63).IsUnicode(false);
                pn.Property(p=>p.Number).HasMaxLength(31).IsUnicode(false);
            });
            builder.HasOne(u=>u.AccessFail).WithOne(f=>f.Myuser).HasForeignKey<UserAccessFail>(f=>f.Userid);
        }
    }
}
